$(function(){
	/**调用初始化方法*/
	queryRole();
});
/*function getAllRole(){
	$.post("/GetAllGoods/",null,function(str){
		str = decodeURI(str);
		var data = $.parseJSON(str);
		for(var i=0;i<data.length;i++){
			$("#selectId").append("<option value='"+data[i].RoleId+"'>"+data[i].RoleName+"</option>");
		}
	});
}*/

/*function queryForm(){
	var userName = $("#queryName").val();
	var roleId = $("#querySelect").val();
	queryRole(userName,roleId);
}*/

function queryRole(){
	$(this).hide();
	$('#usertable').bootstrapTable('destroy');
	$('#usertable').bootstrapTable({
		method: 'get',
		url: '/GetAllChargeType/',
		cache: false,
		striped: true,
		pagination:true,
		pageSize:20,
		pageList: [5, 10, 20,50],
		pageNumber:1,
		sidePagination:'server',
		width:'600',
		columns: [
			{
				field: 'cardTypeId',
				title: 'Item ID',
				align: 'right',
				valign: 'bottom',
				visible:false
			},{
				field: 'cardTitle',
				title: '充值类型名称',
				align: 'center',
				formatter: turnAround,
				valign: 'middle'

			}, {
				field: 'cardRMB',
				title: '实卡RMB价格',
				formatter: turnAround,
				align: 'center',
				valign: 'middle'
			},{
				field: 'cardCoinNum',
				title: '充值卡兑换金币数量',
				formatter: turnAround,
				align: 'center',
				valign: 'middle'
			},{
				field: 'cardMoneyInt',
				title: '充值卡兑换钻石数量',
				formatter: turnAround,
				align: 'center',
				valign: 'middle'
			},{
				field: 'ctime',
				title: '创建时间',
				align: 'center',
				valign: 'middle'

			},{
				field: 'operate',
				title: '操作',
				align: 'center',
				valign: 'middle',
				formatter: operateFormatter,
				events: operateEvents
			}]
	});
}
/**
 * table图标区
 */
function operateFormatter(value, row, index) {
		return [
			'<button class="updateUser" id="updateUser">修改</button>&nbsp'/*,
			'<button class="upGoods" id="up">删除</button>'*/
			].join('');
}

/**
 * 图标绑定点击事件
 */
window.operateEvents = {
		'click .updateUser': function (e, value, row, index) {
			isModify=1;
			$("#titleId").html("修改会员卡类型");
			$(".name").val(decodeURI(row.cardTitle,"utf-8"));
			$(".rmb").val(decodeURI(row.cardRMB*100,"utf-8"));
			$(".coin").val(decodeURI(row.cardCoinNum,"utf-8"));
			$(".damon").val(decodeURI(row.cardMoneyInt,"utf-8"));
			$("#ids").val(row.cardTypeId);
			$("#show_div_user").show();
		},
		'click .upGoods': function (e, value, row, index) {
			var id=row.cardTypeId;
			if(confirm("你确定提交该操作吗？")){
				$.get("/deleteCardType/?id="+id,null,function(data){
					alert(data);
					queryRole();
				});
			}
		}
};
function turnAround(value, row, index){
	return decodeURI(value,"utf-8"); 
}



/* 点击提交的事件  */
$("#addUser").click(function(){
	$(".show_div").hide();
	var data={};
	var name=$(".name").val();
	var rmb=$(".rmb").val();
	var coin=$(".coin").val();
	var damon=$(".damon").val();
	data.name = name;
	data.rmb = rmb;
	data.coin = coin;
	data.damon = damon;
	var userid = $("#ids").val();
	if(userid!=0 && userid!=null){
		data.id = userid;
	}
	if(name&&rmb&&coin&&damon){
		if(confirm("你确定提交该操作吗？")){
			$(this).html('发送中...');
			$(this).css({"background":"#616161"});
			$.get("/addOrUpdateCardType/",data,function(data){
				data = decodeURI(data);
				var data1 = $.parseJSON(data);
				if(data1.state == 1){
					window.location.reload();
					alert(data1.message);
				}else{
					$(".showList_submit").html('提交');
					$(".showList_submit").css({"background":"#438EB9"});
					alert(data1.message);
					$("#show_div_user").show();
				}
			});
		}
	}else{
		alert("填写错误");
	}
});
